/**
 * Copyright (C) 2008 aileron.cc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cc.aileron.commons;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.junit.Test;

import cc.aileron.commons.accessor.PojoAccessor;
import cc.aileron.commons.accessor.PojoAccessorModule;

/**
 * pojo-test3
 * @author Aileron
 *
 */
public class PojoTest3
{
    public static class T
    {
        public String toString()
        {
            return new ReflectionToStringBuilder(this).toString();
        }
        
        public Integer value ;
    }
    
    @Test
    public void test()
    {
        final PojoAccessor<T> pojo = PojoAccessorModule.defaultFactory.accessor(new T()); 
        final Integer a = 10;
        
        pojo.set("value", a);
        assertThat(pojo.getNumber("value").intValue(), equalTo(a));
        
        final int b = 20;
        pojo.set("value", b);
        
        assertThat(pojo.getNumber("value").intValue(), equalTo(b));
        
        final long c = 30;
        pojo.set("value", c);
        
        System.out.println( pojo.toTarget() );
        
        assertThat(pojo.getNumber("value").longValue(), equalTo(c));
    }
}
